package com.government.web.controller.area;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.government.common.annotation.RepeatSubmit;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.government.common.annotation.Log;
import com.government.common.core.controller.BaseController;
import com.government.common.core.domain.AjaxResult;
import com.government.common.enums.BusinessType;
import com.government.area.domain.ParkArea;
import com.government.area.service.IParkAreaService;
import com.government.common.utils.poi.ExcelUtil;

/**
 * 园区信息Controller
 * 
 * @author system
 * @date 2023-10-30
 */
@RestController
@RequestMapping("/area/parkArea")
public class ParkAreaController extends BaseController
{
    @Autowired
    private IParkAreaService parkAreaService;

    /**
     * 查询园区信息列表
     */
    @PreAuthorize("@ss.hasPermi('area:area:list')")
    @GetMapping("/list")
    public AjaxResult list(ParkArea parkArea)
    {
        List<ParkArea> list = parkAreaService.selectParkAreaList(parkArea);
        return success(list);
    }

    /**
     * 导出园区信息列表
     */
    @PreAuthorize("@ss.hasPermi('area:area:export')")
    @Log(title = "园区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ParkArea parkArea)
    {
        List<ParkArea> list = parkAreaService.selectParkAreaList(parkArea);
        ExcelUtil<ParkArea> util = new ExcelUtil<ParkArea>(ParkArea.class);
        util.exportExcel(response, list, "园区信息数据");
    }

    /**
     * 获取园区信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('area:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(parkAreaService.selectParkAreaById(id));
    }

    /**
     * 新增园区信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('area:area:add')")
    @Log(title = "园区信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ParkArea parkArea)
    {
        return toAjax(parkAreaService.insertParkArea(parkArea));
    }

    /**
     * 修改园区信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('area:area:edit')")
    @Log(title = "园区信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ParkArea parkArea)
    {
        return toAjax(parkAreaService.updateParkArea(parkArea));
    }

    /**
     * 删除园区信息
     */
    @RepeatSubmit
    @PreAuthorize("@ss.hasPermi('area:area:remove')")
    @Log(title = "园区信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(parkAreaService.deleteParkAreaByIds(ids));
    }


    /**
     * 园区树
     */
    @GetMapping("/parkAreaTree")
    public AjaxResult parkAreaTree()
    {
        return success(parkAreaService.parkAreaTree());
    }

    /**
     * 小程序获取园区树
     */
    @GetMapping("/wxParkAreaTree")
    public AjaxResult wxParkAreaTree()
    {
        return success(parkAreaService.wxParkAreaTree());
    }

}
